import {
  SET_BANNER_IMAGES,
  SET_HOME_GOODS_INFO,
  SET_GRID_IMAGES,
  SET_GOODS_INFO,
  SET_CATEGORY_INFO,
  SET_USER_INFO,
  SET_LOGIN_TOKEN,
  DELETE_LOGIN_TOKEN,
  SET_CART,
  SET_ADDRESS,
  SET_ORDER,
  SET_ID,
  SET_ORDER_NUM,
  SET_ORDER_ITEM,
  SET_CART_COUNT,
  SET_GOODS_ITEM,
  SET_GOODS_SEARCH_ITEMS
} from './types.js'
export default {
  // 一般我们会将JSON存入localStorage中，但是在localStorage会自动将localStorage转换成为字符串形式
  // 可以用JSON.stringify()将JSON转为JSON字符串
  // 读取之后要将JSON字符串转换成为JSON对象，使用JSON.parse()方法
  // 添加轮播图信息
  [SET_BANNER_IMAGES](state, images) {
    state.bannerImages = images
    localStorage.setItem('bannerImages', JSON.stringify(images))
  },
  // 添加主页商品信息
  [SET_HOME_GOODS_INFO](state, info) {
    state.homeGoodsInfo = info
    localStorage.setItem('homeGoodsInfo', JSON.stringify(info))
  },
  // 添加主页宫格图
  [SET_GRID_IMAGES](state, info) {
    state.gridImages.info = info
    localStorage.setItem('gridImages', JSON.stringify(info))
  },
  // 添加主页商品信息
  [SET_GOODS_INFO](state, info) {
    state.goodsInfo.info = info
    localStorage.setItem('goodsInfo', JSON.stringify(info))
  },
  // 添加分类信息
  [SET_CATEGORY_INFO](state, info) {
    state.category.info = info
    localStorage.setItem('category', JSON.stringify(info))
  },
  // 添加用户信息
  [SET_USER_INFO](state, info) {
    state.userInfo = info
    localStorage.setItem('userInfo', JSON.stringify(info))
  },
  // 添加token
  [SET_LOGIN_TOKEN](state, info) {
    state.loginToken = info
    localStorage.setItem('loginToken', JSON.stringify(info))
  },
  // 删除token
  [DELETE_LOGIN_TOKEN](state) {
    state.loginToken = {}
    localStorage.removeItem('loginToken')
  },
  // 添加购物车信息
  [SET_CART](state, info) {
    state.shopCart = info
    localStorage.setItem('shopCart', JSON.stringify(info))
  },
  // 添加购物车信息
  [SET_CART_COUNT](state, info) {
    state.cartCount = info
  },
  // 添加收货地址
  [SET_ADDRESS](state, info) {
    state.address = info
    localStorage.setItem('address', JSON.stringify(info))
  },
  // 添加订单列表
  [SET_ORDER](state, info) {
    state.order = info
    localStorage.setItem('order', JSON.stringify(info))
  },
  //
  [SET_ID](state, str) {
    state.id = str
  },
  // order_num
  [SET_ORDER_NUM](state, str) {
    state.orderNum = str
  },
  // 设置传到orderConfirm页面的数据
  [SET_GOODS_ITEM](state, str) {
    state.goodsItem = str
  },
  // 设置传到搜索页面的数据
  [SET_GOODS_SEARCH_ITEMS](state, str) {
    state.goodsSearchItems = str
  },
  [SET_ORDER_ITEM](state, info) {
    state.orderItem = info
    localStorage.setItem('orderItem', JSON.stringify(info))
  }
}
